/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.buku;

import com.ivanbiz.generic.GenericDAOImpl;
import java.util.List;
import org.hibernate.Query;

/**
 *
 * @author User
 */
public class BukuDAOImpl extends GenericDAOImpl implements BukuDAO {

    public boolean cekIsEmptyKode(String kode) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from Buku b where b.kodeBuku=:kode");
        query.setString("kode", kode);
        if (query.uniqueResult() != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean cekFlagBuku(String kode,String flag) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from Buku b where b.kodeBuku=:kode and b.flag=:flag");
        query.setString("kode", kode);
        query.setString("flag", flag);
        if (query.uniqueResult() != null) {
            return true;
        } else {
            return false;
        }
    }
    

    public List cariBuku(String nama,String flag) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from Buku b where b.namaBuku like :nama and b.flag=:flag'");
        query.setParameter("nama", "%" + nama + "%");
        query.setParameter("flag",flag);
        return query.list();    
    }
}
